uniform vec3 iResolution;
uniform float iTime;

#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif

#define s smoothstep
#define pi 3.1415
#define res iResolution.xy
#define t iTime


/////////////// changeable variables ////////////////

float num = 60.;
#define zoom 1.1
#define have_fun .0
#define have_fun2 .0

/////////////////////////////////////////////////////


mat2 rot(float a){
  float s=sin(a),c=cos(a);
  return mat2(c,-s,s,c);
}

float rand(float f){
  return fract(sin(f*254.343)*532.327);
}

vec4 ember(vec2 uv, float brightness, float size, float num){
  float flarealpha;
  vec3 flarexyz;
  float d, b, l;
  float a = res.x/res.y;
  float yanker = sin(t*2.)*.1+.1;

  /*
  for (float i; i<=num; i++){
    b = (brightness*rand(i*362.123))*(sin(t*rand(i*135.13)*10.)*.5+.75);
    d = b/length(uv-vec2(
      sin(t*1.+i)*.1+mix(-.5*a, .5*a, rand(i+1.)),
      fract(t*mix(.3, 1., rand(i))*.2+i*532.632)*1.5-.75)
    );
    flare += vec3(d) * vec3(1., s(-.5+yanker, .5+yanker, uv.y)*.3+.2*rand(i*651.4134), .1);
  }
  */

  for (float i; i<=num; i++){
    b = (brightness*rand(i*362.123))*(sin(t*rand(i*135.13)*10.)*.5+.75);
    d = b/length(uv-vec2(
      sin(t*1.+i)*.1+mix(-.5*a, .5*a, rand(i+1.)),
      fract(t*mix(.3, 1., rand(i))*.2+i*532.632)*1.5-.75)
    );
    l = s(-.5+yanker, .5+yanker, uv.y)*.3+.2*rand(i*651.4134);
    flarexyz += vec3(d) * vec3(1.-2.*l, .7, 2.*l);
    flarealpha += pow(d, 1.3);
  }
  return vec4(flarexyz, flarealpha);
}

float N(vec2 uv, vec2 p){
  uv -= p;
  float lr = step(uv.x, .185)*step(-.185, uv.x);
  float tb = step(uv.y, .225)*step(-.225, uv.y);
  float tt = step(uv.x+uv.y-.025, .0)+step(.15, uv.x);
  float bt = step(.0, uv.x+uv.y+.025)+step(uv.x, -.15);

  return clamp(lr*tb*tt*bt, .0, 1.);
}

float E(vec2 uv, vec2 p){
  uv -= p;
  float lr = step(uv.x, .14)*step(-.14, uv.x);
  float tb = step(uv.y, .225)*step(-.225, uv.y);
  float ts = 1.-step(.0225, uv.y)*step(uv.y, .185)*step(-.1, uv.x);
  float bs = 1.-step(-.185, uv.y)*step(uv.y, -.0225)*step(-.1, uv.x);
  float sculp = 1.-step(uv.x-uv.y,.1)*step(.06, uv.x-uv.y)*step(uv.y,-.1);

  return lr*tb*ts*bs*sculp;
}

float O(vec2 uv, vec2 p){
  uv -= p;
  float d = s( .2275, .2225,length(uv))*s(.18, .185, length(uv));
  float sculp = 1.-step(uv.x-uv.y,.025)*step(-.025, uv.x-uv.y)*step(.0,uv.y);

  return d*sculp;
}

uniform vec2 resolution;
uniform float time;

void main(){
  vec2 uv = (gl_FragCoord.xy-.5*res)/res.y;
  vec2 uv2 = uv;

  uv2 *= zoom;
  uv2 *= rot(have_fun2);

  vec3 col = vec3(.0);

  //vec3 NEO_Shade = vec3(s(-.5, .3, uv2.y), s(-.2, .5, uv2.y)*.75, s(.0, -1., uv2.y));

  //float n = clamp(N(uv2, vec2(-.5, .0)), .0, 1.);
  //float e = E(uv2, vec2(.0));
  //float o = O(uv2, vec2(.5, .0));

  //col += n*NEO_Shade;
  //col += e*NEO_Shade;
  //col += o*NEO_Shade;

  //col += s(.1*sin(t)+.25, 1.5, length(uv))*vec3(.5, .1, .0);

  uv *= rot(have_fun);

  // holy shit I can layer stuff now????????????
  vec4 col4 = ember(uv, .004, .1, num);
  // col += clamp(ember(uv, .004, .1, num), .0, 1.-(n+e+o));

  gl_FragColor = col4;
}